//
//  SendLineController.m
//  NtoccShipper
//
//  Created by 张天兴 on 2023/8/21.
//  Copyright © 2023 zhuchongjin. All rights reserved.
//

#import "SendLineController.h"
#import "SourceListCell.h"
#import "SourceListDetailVC.h"
#import "SourcesOrderVC.h"
#import "SourceListModel.h"
#import "SendGoodsVC.h"
#import "BiddingDriverListVC.h"
#import "AdjustPriceVC.h"
#import "BiddDriverListModel.h"
#import "AddLineItemController.h"
@interface SendLineController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong) SourceListCell *sourceListCell;
@property (nonatomic,strong) CJTableView *tableView;
@property (nonatomic,strong) NSMutableArray *modelArray;
@property (nonatomic,strong) NSString *refreshType; //刷新
@property (nonatomic,readwrite) int page;
@property (copy, nonatomic) NSString *strStatus; // 货源状态
@property (nonatomic,copy) NSString *strIsOftenOrder;  // 0不是 1是
@property (nonatomic,copy) NSString *strIsCancel; // 0不是 1是
//@property (strong, nonatomic) NSDictionary *dicSearch;
@property (nonatomic, strong) UIView* bgView;

@property (nonatomic, strong) UIView* erwmView;

@property (nonatomic, strong) UIImageView *erwmImagView;

@property (nonatomic, strong) UILabel *infroLabel;

@property (nonatomic, strong) UILabel *zhAddLabel;

@property (nonatomic, strong) UILabel *zhDetileAddLabel;

@property (nonatomic, strong) UILabel *xhAddLabel;

@property (nonatomic, strong) UILabel *xhDetileAddLabel;

@property (nonatomic, strong) UILabel *zhStateTime;

@property (nonatomic, strong) UILabel *xhEndTime;
@property (nonatomic, strong) UITapGestureRecognizer *changeVoidceSet;

@property (nonatomic, strong) UIButton *buttonImag;
@property (nonatomic, strong) NSMutableArray *titAddArr;
@property (nonatomic, strong) UIButton *addItemButton;
@end

@implementation SendLineController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setTitleName:CJLString(@"项目线路货源")];
    [self setBackLeftButton:@""];
    [self.view addSubview:self.tableView];
    [self.view addSubview:self.addItemButton];
    WS(ws);
    self.tableView.placeHolderView = [[KKTableViewNoDataView alloc] initWithFrame:self.tableView.bounds image:[UIImage imageNamed:@"no_data"] viewClick:^{
       [ws.tableView.mj_header beginRefreshing];
    }];
    [self initData];
    
    if ([CJControl isLogin]) {
        [self loadData];
    }
    
    CJRegisterNotify(@"BiddDriverListModel", @selector(adjustDriverAction:));
    CJRegisterNotify(@"clickTabBarReloadData", @selector(clickTabBarReloadData));
    CJRegisterNotify(@"searchSourcesListAction", @selector(searchSourcesListAction:))
}

- (void)clickTabBarReloadData{
    if ([CJControl isLogin]) {
        [self.tableView.mj_header beginRefreshing];
    }
}

- (void)searchSourcesListAction:(NSNotification *)notification{
//      BiddDriverListModel *list = (BiddDriverListModel *)notification.object
//    self.dicSearch = (NSDictionary *)notification.object;
    [self.tableView.mj_header beginRefreshing];
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:YES];
    
    if ([CJControl isLogin]) {
        [self.tableView.mj_header beginRefreshing];
    }
}

- (void)initData{
    self.modelArray = [[NSMutableArray alloc]init];
    self.page = 1;
}

- (void)loadData {
    NSString *strURL = CJStringWithFormat(@"%@/ntocc-tms-api/orderProjectRoutes/list",CJBaseUrl);
    NSDictionary *dicPar = @{
        @"pageNum":CJStringWithFormat(@"%d",self.page),
        @"pageSize":@"10",
        @"projectName":self.projectName,
    };
//
    WS(ws);
    [[HDNetworking sharedHDNetworking] GET:strURL parameters:dicPar success:^(id  _Nonnull responseObject) {

        NSArray *list = responseObject[@"records"];
        NSString *total = CJStringWithFormat(@"%@",responseObject[@"total"]);
        //            if (list.count > 0) {
        if ([ws.refreshType isEqualToString:@"down"]) {
            [ws.modelArray removeAllObjects];
        }

        NSError * error ;
        NSArray *arr = [SourceListModel arrayOfModelsFromDictionaries:list error:&error];
        [ws.modelArray addObjectsFromArray:arr];

        [ws.tableView.mj_header endRefreshing];
        [ws.tableView.mj_footer endRefreshing];
        //                DLog(@"当前返回====== %lu",(unsigned long)list.count);
        //                DLog(@"==== %lu",(unsigned long)self.modelArray.count);
        //                DLog(@"total==== %@",total);
        //                DLog(@"=======dic =  %@",dicPar);
        if (ws.modelArray.count == total.intValue) {
            [ws.tableView.mj_footer endRefreshingWithNoMoreData];
        }
        //            }else{

        //                [ws.tableView.mj_header endRefreshing];
        //                [ws.tableView.mj_footer endRefreshingWithNoMoreData];
        //            }
        [ws.tableView reloadData];
    } failure:^(NSError * _Nonnull error) {
        DLog(@"++++++++%@",error);
        [ws.tableView.mj_header endRefreshing];
        [ws.tableView.mj_footer endRefreshing];
    }];
}

- (void)downRefresh{
    self.refreshType = @"down";
    self.page = 1;
    [self loadData];
}

- (void)upRefresh{
    self.refreshType = @"up";
    self.page ++;
    [self loadData];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.modelArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *identifier = @"SourceListCell";
    SourceListCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil) {
        cell = [[SourceListCell alloc] initWithFlex:[CJControl getUIWithNew] ? @"SourceListCellNew":@"SourceListCell" reuseIdentifier:identifier];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    SourceListModel *model = self.modelArray[indexPath.row];
    [cell setCellInfoWithSourceModel:model];
    
    WS(ws);
    cell.blockDetail = ^(id anyObject) {
        [ws btnGoToOrderDetail:model];
    };
    
    cell.blcokAgain = ^(id anyObject) {
        [ws btnSendOrderAgain:model];
    };
    
    cell.blockStop = ^(id anyObject) {
        [ws btnStopOrderAction:model withIndex:indexPath];
    };
    
    cell.blcokRefresh = ^(id anyObject) {
        [ws btnRefreshOrder:model withIndex:indexPath];
    };
    
    cell.blcokPrice = ^(id anyObject) {
        [ws btnMakePrice:model];
    };
    
    cell.blockDelecte = ^(id anyObject) {
        [ws btnDelecteOrderAction:model];
    };
    
    cell.blockAdjustPrice = ^(id anyObject) {
        [ws btnAdjustPriceAction:model];
    };
    
    cell.QRCodeDelegate = ^(id anyObjecct){
        [[UIApplication sharedApplication].keyWindow addSubview:self.bgView];
        [self NetworkReweima:model.code];
        self.titAddArr = [NSMutableArray array];
        [self.titAddArr addObject:CJStringWithFormat(@"%@",model.coalTypeName)];
        [self.titAddArr addObject:CJStringWithFormat(@"%@",model.shipperAddress)];
        [self.titAddArr addObject:CJStringWithFormat(@"%@",model.shipperDetailAddress)];
        [self.titAddArr addObject:CJStringWithFormat(@"%@",model.consigneeAddress)];
        [self.titAddArr addObject:CJStringWithFormat(@"%@",model.consigneeDetailAddress)];
        [self.titAddArr addObject:CJStringWithFormat(@"%@",model.lastLoadingTime)];
        [self.titAddArr addObject:CJStringWithFormat(@"%@",model.lastUnloadingTime)];
        self.infroLabel.attributedText = [self stringColorStr:@"货物信息:" String:self.titAddArr.firstObject Color:[UIColor blueColor]];
        self.zhAddLabel.attributedText = [self stringColorStr:@"装货市区:" String:self.titAddArr[1] Color:[UIColor blueColor]];
        self.zhDetileAddLabel.attributedText = [self stringColorStr:@"详细地址:" String:self.titAddArr[2] Color:[UIColor blueColor]];
        self.xhAddLabel.attributedText = [self stringColorStr:@"卸货市区:" String:self.titAddArr[3] Color:[UIColor blueColor]];
        self.xhDetileAddLabel.attributedText = [self stringColorStr:@"详细地址:" String:self.titAddArr[4] Color:[UIColor blueColor]];
        self.zhStateTime.attributedText = [self stringColorStr:@"装车时间:" String:self.titAddArr[5] Color:[UIColor blueColor]];
        self.xhEndTime.attributedText = [self stringColorStr:@"卸货时间:" String:self.titAddArr.lastObject Color:[UIColor blueColor]];
    };
    
    cell.blockFinish = ^(id anyObject) {
        [ws btnFinishOrderAction:model];
    };
    
//    cell.blcokSendOrders = ^(id anyObject) {
//        [ws btnSenderOrders:model];
//    };
    cell.blockChange = ^(id anyObject) {
        [ws btnChangeOrderAction:model];
    };
//    cell.blockPush = ^(id anyObject) {
//        [ws btnPushOrders:model];
//    };
    
    return cell;
 
}
- (void)NetworkReweima:(NSString *)codID{
    NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
    [dict setValue:codID forKey:@"mainOrderCode"];
    [[HDNetworking sharedHDNetworking] GET:CJStringWithFormat(@"%@/ntocc-test-api/QrTakeOrder/testToAndroid",CJBaseUrl) parameters:dict success:^(id  _Nonnull responseObject) {
        NSData* data = [[NSData alloc] initWithBase64EncodedString:responseObject options:0];
        
        self.erwmImagView.image = [UIImage imageWithData:data];
        

    } failure:^(NSError * _Nonnull error) {
        DLog(@"++++++++%@",error);
        
    }];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    SourceListModel *model = self.modelArray[indexPath.row];
    SourcesOrderVC *vc = [[SourcesOrderVC alloc]init];
    vc.strCode = model.code;
    [self pushVc:vc];
}

#pragma mark ----------btn
/// 详情
/// @param model <#model description#>
- (void)btnGoToOrderDetail:(SourceListModel *)model{
    
    SourceListDetailVC *vc = [[SourceListDetailVC alloc]init];
    vc.strCode = model.code;
    [self pushVc:vc];
}
/// 在再来一单
/// @param model <#model description#>
- (void)btnSendOrderAgain:(SourceListModel *)model{
    
    WS(ws);
    CJAlertView *alert = [[CJAlertView alloc]initWithTitle:@"" strContent:@"您确定要再来一单吗？" ClickOnSure:^(NSString * _Nonnull strSure) {

        [CJNetWork getSourcesListDetailDataWithCode:model.code Success:^(id  _Nullable responseObject) {

            SendGoodsVC *vc = [[SendGoodsVC alloc]init];
            vc.strIsAgainOrder = @"1";
            vc.sourceListModel = (SourceListDetailModel *)responseObject;
            [ws pushVc:vc];
        }];

    } ClickOnCancle:^(NSString * _Nonnull strCancle) {

    }];
    alert.center = KEYWINDOW.center;
    WLAlertView * alertView = [[WLAlertView alloc]init];
    alertView.containerView = alert;
    [alertView show];
}
/// 修改
/// @param model <#model description#>
- (void)btnChangeOrderAction:(SourceListModel *)model{
    
    WS(ws);
    CJAlertView *alert = [[CJAlertView alloc]initWithTitle:@"" strContent:@"您确定要修改订单吗？" ClickOnSure:^(NSString * _Nonnull strSure) {
        
        [CJNetWork getSourcesListDetailDataWithCode:model.code Success:^(id  _Nullable responseObject) {
            SendGoodsVC *vc = [[SendGoodsVC alloc]init];
            vc.strIsChangeOrder = @"1";
            vc.strOrderCode = model.code;
            vc.sourceListModel = (SourceListDetailModel *)responseObject;
            [ws pushVc:vc];
        }];
        
        
    } ClickOnCancle:^(NSString * _Nonnull strCancle) {
        
    }];
    alert.center=KEYWINDOW.center;
    WLAlertView * alertView = [[WLAlertView alloc]init];
    alertView.containerView = alert;
    alertView.isTouchOtherUndissmiss = YES;
    [alertView show];
}
/// 暂停
/// @param model <#model description#>
- (void)btnStopOrderAction:(SourceListModel *)model withIndex:(NSIndexPath* )index{
    WS(ws);
    CJAlertView *alert = [[CJAlertView alloc]initWithTitle:@"" strContent:@"订单暂停后司机不可接单！确认要暂停订单吗？" ClickOnSure:^(NSString * _Nonnull strSure) {
        
        [CJNetWork stopOrderListWithCodes:model.code Success:^(id  _Nullable responseObject) {
        
            model.isCancel = 1;
            model.isFinishOrder = 0;
            [ws.tableView reloadRowAtIndexPath:index withRowAnimation:UITableViewRowAnimationNone];
            
        }];
    } ClickOnCancle:^(NSString * _Nonnull strCancle) {
      
    }];
    
    alert.center = KEYWINDOW.center;
    WLAlertView * alertView = [[WLAlertView alloc]init];
    alertView.containerView = alert;
    alertView.isTouchOtherUndissmiss=YES;
    [alertView show];
}
/// 刷新
/// @param model <#model description#>
- (void)btnRefreshOrder:(SourceListModel *)model withIndex:(NSIndexPath* )index{
    
   WS(ws);
   CJAlertView *alert = [[CJAlertView alloc]initWithTitle:@"" strContent:@"确定要向司机重新推送本单吗？" ClickOnSure:^(NSString * _Nonnull strSure) {
       
       [CJNetWork refreshOrderListWithCodes:model.code Success:^(id  _Nullable responseObject) {
           DLog(@"++++ %@",responseObject);
           model.isCancel = 0;
           model.status = 0;
           [ws.tableView reloadRowAtIndexPath:index withRowAnimation:UITableViewRowAnimationNone];

       }];
   } ClickOnCancle:^(NSString * _Nonnull strCancle) {
     
   }];
   
   alert.center = KEYWINDOW.center;
   WLAlertView * alertView = [[WLAlertView alloc]init];
   alertView.containerView = alert;
   alertView.isTouchOtherUndissmiss=YES;
   [alertView show];
}


/// 调单
/// @param notification <#notification description#>
- (void)adjustDriverAction:(NSNotification *)notification{
      BiddDriverListModel *list = (BiddDriverListModel *)notification.object;
    
    NSString *strURL = CJStringWithFormat(@"%@/ntocc-tms-api/orderBid/selectBid",CJBaseUrl);
    NSDictionary *dicPar = @{@"code":list.code,
                             @"driverCode":list.driverCode,
                             @"selectBidWeight":CJStringWithFormat(@"%@",@(list.selectBidWeight).cj_description),
                             @"selectBidCount":CJStringWithFormat(@"%@",list.selectBidCount)
    };
    
    WS(ws);
    [[HDNetworking sharedHDNetworking] POST:strURL parameters:dicPar success:^(id  _Nonnull responseObject) {
        
        DLog(@"++++++++%@",responseObject);
        [ws.tableView.mj_header beginRefreshing];
    } failure:^(NSError * _Nonnull error) {
        DLog(@"++++++++%@",error);
        
    }];
}


/// 竞价
/// @param model <#model description#>
- (void)btnMakePrice:(SourceListModel *)model{
//    [CJAlert showStringDismissWithDelay:@"隐私协议"];
    BiddingDriverListVC *vc = [[BiddingDriverListVC alloc]init];
    vc.strCode = model.code;
    vc.blockSuccess = ^(id anyObject) {
        
        //selectBidWeight   selectBidCount  code  driverCode
        BiddDriverListModel *mod = (BiddDriverListModel *)anyObject;
        NSString *strURL = CJStringWithFormat(@"%@/ntocc-tms-api/orderBid/selectBid",CJBaseUrl);
        NSDictionary *dicPar = @{@"code":mod.code,
//                                 @"driverCode":mod.driverCode,
                               @"selectBidWeight":CJStringWithFormat(@"%0.2f",mod.selectBidWeight),
//                                 @"selectBidCount":CJStringWithFormat(@"%0.2f",mod.selectBidCount)
        };
        
        WS(ws);
        [[HDNetworking sharedHDNetworking] POST:strURL parameters:dicPar success:^(id  _Nonnull responseObject) {
//            DLog(@"++++++++%@",responseObject);
            [ws.tableView.mj_header beginRefreshing];
        } failure:^(NSError * _Nonnull error) {
            DLog(@"++++++++%@",error);
            
        }];
    };
    
    [self pushVc:vc];
}
///// 派单
///// @param model <#model description#>
//- (void)btnSenderOrders:(SourceListModel *)model{
//    [CJAlert showStringDismissWithDelay:@"隐私协议"];
//}
//- (void)btnPushOrders:(SourceListModel *)model{
//    [CJAlert showStringDismissWithDelay:@"隐私协议"];
//}

- (void)btnFinishOrderAction:(SourceListModel *)model{
    
    WS(ws);
    CJAlertView *alert = [[CJAlertView alloc]initWithTitle:@"提示" strContent:@"您确定要结束货源吗" ClickOnSure:^(NSString * _Nonnull strSure) {
        
        NSString *strURL = CJStringWithFormat(@"%@/ntocc-tms-api/order/finishOrder",CJBaseUrl);
        NSDictionary *dicPar = @{
                                 @"codes":model.code,
        };
        
        [[HDNetworking sharedHDNetworking] dataTaskWithHTTPMethod:PutType url:strURL parameters:dicPar status:OperationTip success:^(id  _Nonnull responseObject) {
            
            [ws.tableView.mj_header beginRefreshing];
        } failure:^(NSError * _Nonnull error) {
            
        }];
    } ClickOnCancle:^(NSString * _Nonnull strCancle) {
      
    }];
    
    alert.center = KEYWINDOW.center;
    WLAlertView * alertView = [[WLAlertView alloc]init];
    alertView.containerView = alert;
    alertView.isTouchOtherUndissmiss=YES;
    [alertView show];
}

/// 删除
/// @param model <#model description#>
- (void)btnDelecteOrderAction:(SourceListModel *)model{
    
    WS(ws);
    CJAlertView *alert = [[CJAlertView alloc]initWithTitle:@"提示" strContent:@"删除订单后不可恢复！确认要删除订单吗？" ClickOnSure:^(NSString * _Nonnull strSure) {
        
        [CJNetWork deleteOrderListWithCodes:model.code Success:^(id  _Nullable responseObject) {
            DLog(@"++++ %@",responseObject);
            [ws.tableView.mj_header beginRefreshing];
        }];
    } ClickOnCancle:^(NSString * _Nonnull strCancle) {
      
    }];
    
    alert.center = KEYWINDOW.center;
    WLAlertView * alertView = [[WLAlertView alloc]init];
    alertView.containerView = alert;
    alertView.isTouchOtherUndissmiss=YES;
    [alertView show];
}

- (void)btnAdjustPriceAction:(SourceListModel *)model{
    WS(ws);
    AdjustPriceVC *vc = [[AdjustPriceVC alloc]init];
    vc.strCode = model.code;
    vc.model = model;
    vc.blockSuccess = ^(id anyObject) {
        [ws.tableView.mj_header beginRefreshing];
    };
    [self pushVc:vc];
}

- (void)pushVc:(UIViewController *)vc {
    
    if ([vc isKindOfClass:[UIViewController class]] == NO) return ;
    if (self.navigationController == nil) return ;
    if (vc.hidesBottomBarWhenPushed == NO) {
        vc.hidesBottomBarWhenPushed = YES;
    }
    
    [self.navigationController pushViewController:vc animated:YES];
}

- (CJTableView *)tableView{
    if (!_tableView) {
        _tableView = CJTableView.tbInitFrameStyle(CGRectMake(0, CJTableToTopHeight + kTopHeight, SCREEN_WIDTH, SCREEN_HEIGHT-kTopHeight - kNavBarHeight -CJTableToTopHeight - 50  ),UITableViewStylePlain)
        .tbDelegate(self)
        .tbDataSource(self)
        .tbSetOther(YES)
        .tbEstimatedRowHeight(YES)
        .tbMjHeadFooter(YES)
        ;
        WS(ws);
        _tableView.blockMjHeader = ^(BOOL isheader) {
            
            if (isheader) {
                [ws downRefresh];
            } else {
                [ws upRefresh];
            }
        };
    }
    return _tableView;
}
- (UIButton *)addItemButton{
    if(_addItemButton == nil){
        self.addItemButton = [UIButton buttonWithType:(UIButtonTypeSystem)];
        [self.addItemButton setFrame:CGRectMake(10, SCREEN_HEIGHT - kStatusBarHeight - 50, SCREEN_WIDTH - 20, 50)];
        [self.addItemButton setTitle:@"发布货源" forState:(UIControlStateNormal)];
        [self.addItemButton setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
        self.addItemButton.backgroundColor = [UIColor cjMainColor];
        [self.addItemButton addTarget:self action:@selector(addItemButtonAction) forControlEvents:(UIControlEventTouchUpInside)];
        self.addItemButton.layer.masksToBounds = YES;
        self.addItemButton.layer.cornerRadius = 10;
    }
    return _addItemButton;
}
- (void)addItemButtonAction{
    AddLineItemController *addVC = [[AddLineItemController alloc] init];
    [self pushVc:addVC];
}
-(UIView *)bgView{
    if (!_bgView) {
        self.bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
        self.bgView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.6];
        self.changeVoidceSet = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(changeVoidceSet:)];
        [self.bgView addGestureRecognizer:self.changeVoidceSet];
        [self.bgView addSubview:self.erwmView];
        [self.bgView addSubview:self.buttonImag];
    }
    return _bgView;
}
- (UIView *)erwmView{
    if (!_erwmView) {
        self.erwmView = [[UIView alloc] initWithFrame:CGRectMake(20, (SCREEN_HEIGHT - SCREEN_WIDTH - 40)/2, SCREEN_WIDTH - 40, SCREEN_WIDTH - 40)];
        self.erwmView.backgroundColor = [UIColor whiteColor];
        [self.erwmView addSubview:self.infroLabel];
        [self.erwmView addSubview:self.zhAddLabel];
        [self.erwmView addSubview:self.zhDetileAddLabel];
        [self.erwmView addSubview:self.xhAddLabel];
        [self.erwmView addSubview:self.xhDetileAddLabel];
        [self.erwmView addSubview:self.zhStateTime];
        [self.erwmView addSubview:self.xhEndTime];
        [self.erwmView addSubview:self.erwmImagView];
        self.erwmView.layer.masksToBounds = YES;
        self.erwmView.layer.cornerRadius = 10;
    }
    return _erwmView;
}
- (UILabel *)infroLabel{
    if(!_infroLabel){
        self.infroLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 5, SCREEN_WIDTH - 55, 20)];
        self.infroLabel.textColor = [UIColor cjSubheadTextColor];
        self.infroLabel.font = [UIFont systemFontOfSize:15];
    }
    return _infroLabel;
}
- (UILabel *)zhAddLabel{
    if(!_zhAddLabel){
        self.zhAddLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, CGRectGetMaxY(self.infroLabel.frame) + 5, SCREEN_WIDTH - 55, 20)];
        self.zhAddLabel.textColor = [UIColor cjSubheadTextColor];
        self.zhAddLabel.font = [UIFont systemFontOfSize:15];
    }
    return _zhAddLabel;
}
- (UILabel *)zhDetileAddLabel{
    if(!_zhDetileAddLabel){
        self.zhDetileAddLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, CGRectGetMaxY(self.zhAddLabel.frame) + 5, SCREEN_WIDTH - 55, 20)];
        self.zhDetileAddLabel.textColor = [UIColor cjSubheadTextColor];
        self.zhDetileAddLabel.font = [UIFont systemFontOfSize:15];
    }
    return _zhDetileAddLabel;
}
- (UILabel *)xhAddLabel{
    if(!_xhAddLabel){
        self.xhAddLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, CGRectGetMaxY(self.zhDetileAddLabel.frame) + 5, SCREEN_WIDTH - 55, 20)];
        self.xhAddLabel.textColor = [UIColor cjSubheadTextColor];
        self.xhAddLabel.font = [UIFont systemFontOfSize:15];
    }
    return _xhAddLabel;
}
- (UILabel *)xhDetileAddLabel{
    if(!_xhDetileAddLabel){
        self.xhDetileAddLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, CGRectGetMaxY(self.xhAddLabel.frame) + 5, SCREEN_WIDTH - 55, 20)];
        self.xhDetileAddLabel.textColor = [UIColor cjSubheadTextColor];
        self.xhDetileAddLabel.font = [UIFont systemFontOfSize:15];
    }
    return _xhDetileAddLabel;
}
- (UILabel *)zhStateTime{
    if(!_zhStateTime){
        self.zhStateTime = [[UILabel alloc] initWithFrame:CGRectMake(15, CGRectGetMaxY(self.xhDetileAddLabel.frame) + 5, SCREEN_WIDTH - 55, 20)];
        self.zhStateTime.textColor = [UIColor cjSubheadTextColor];
        self.zhStateTime.font = [UIFont systemFontOfSize:15];
    }
    return _zhStateTime;
}
- (UILabel *)xhEndTime{
    if(!_xhEndTime){
        self.xhEndTime = [[UILabel alloc] initWithFrame:CGRectMake(15, CGRectGetMaxY(self.zhStateTime.frame) + 5, SCREEN_WIDTH - 55, 20)];
        self.xhEndTime.textColor = [UIColor cjSubheadTextColor];;
        self.xhEndTime.font = [UIFont systemFontOfSize:15];
    }
    return _xhEndTime;
}
- (UIImageView *)erwmImagView{
    if (!_erwmImagView) {
        self.erwmImagView = [[UIImageView alloc] initWithFrame:CGRectMake(((SCREEN_WIDTH - 40) - (SCREEN_WIDTH -220))/2 , (SCREEN_WIDTH - 40) - (SCREEN_WIDTH - 220), SCREEN_WIDTH -220, SCREEN_WIDTH - 220)];
//        self.erwmImagView.backgroundColor = [UIColor redColor];
    }
    return _erwmImagView;
}
-(UIButton *)buttonImag{
    if (!_buttonImag) {
        self.buttonImag = [UIButton buttonWithType:(UIButtonTypeSystem)];
        [self.buttonImag setTitle:@"保存图片" forState:(UIControlStateNormal)];
        self.buttonImag.backgroundColor = CJRGBAColor(53, 170, 71, 1);
        [self.buttonImag setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
        self.buttonImag.frame = CGRectMake(20,CGRectGetMaxY(self.erwmView.frame) + 10, SCREEN_WIDTH - 40, 44);
        self.buttonImag.layer.masksToBounds = YES;
        self.buttonImag.layer.cornerRadius = 22;
        [self.buttonImag addTarget:self action:@selector(buttonImagAction) forControlEvents:(UIControlEventTouchUpInside)];
    }
    return _buttonImag;
}
- (void)changeVoidceSet:(UITapGestureRecognizer *)sender{
    if(CGRectContainsPoint(self.erwmView.frame, [sender locationInView:self.bgView])){

    }else{
        [self.bgView removeFromSuperview];
    }

}
- (void)buttonImagAction{
        [self.bgView removeFromSuperview];
    //把view生成图片保存
    UIImageWriteToSavedPhotosAlbum([self convertViewToImage:self.erwmView], self, @selector(image:didFinishSavingWithError:contextInfo:), NULL);

}
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo;
{
    if (error) {
        [CJAlert showStringDismissWithDelay:@"保存失败"];
        [self.bgView removeFromSuperview];
    } else {
        [CJAlert showStringDismissWithDelay:@"保存成功"];
        [self.bgView removeFromSuperview];
    }
}
- (NSMutableAttributedString *)stringColorStr:(NSString *)str String:(NSString *)string Color:(UIColor*)color{
    //Label不同字显示不同颜色
    NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@%@",str,string]];
    NSRange redRange = NSMakeRange([[noteStr string] rangeOfString:string].location, [[noteStr string] rangeOfString:string].length);
    //需要设置的位置
    [noteStr addAttribute:NSForegroundColorAttributeName value:color range:redRange];
    return noteStr;
}
- (UIImage*)convertViewToImage:(UIView*)v{
    CGSize s = v.bounds.size;
    // 下面方法，第一个参数表示区域大小。第二个参数表示是否是非透明的。如果需要显示半透明效果，需要传NO，否则传YES。第三个参数就是屏幕密度了
    UIGraphicsBeginImageContextWithOptions(s, NO, [UIScreen mainScreen].scale);
    [v.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage*image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}
@end
